package com.yls.except.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 银行卡绑定dao
 * Created by xs on 2016/8/3.
 */
@Repository(value="bankDao")
public interface BankDao {

    /**
     * 根据用户id查询用户绑定银行卡信息
     * @param map
     * @return 用户绑定银行卡信息
     */
    @Select("select binding_num,uid,bankname,address,banknum,binding_time,binding_ip,name,card,phone,isdisabled from lrs_bank_binding where uid=#{uid} limit #{start}, #{count}")
    List<Map<String,Object>> selectBankInfoByUid(Map<String, Object> map);

    /**
     * 修改银行卡绑定
     * @param bankinfo 绑定信息
     * @return 修改状态（大于0成功，否则失败）
     */
    @Update("update lrs_bank_binding set " +
            "uid=#{uid},bankname=#{bankname},address=#{address},banknum=#{banknum},binding_time=#{binding_time},binding_ip=#{binding_ip},name=#{name},card=#{card},phone=#{phone},isdisabled=#{isdisabled} " +
            "where binding_num=#{binding_num}")
    int updateBankInfo(Map<String, Object> bankinfo);

    /**
     * 新增银行卡绑定
     * @param bankinfo 银行卡绑定信息
     * @return 新增状态（大于0成功，否则失败）
     */
    @Insert("insert into lrs_bank_binding " +
            "(bankname,address,uid,banknum,binding_time,binding_ip,name,phone,isdisabled) " +
            "values " +
            "(#{bankname},#{address},#{uid},#{banknum},#{binding_time},#{binding_ip},#{name},#{phone},#{isdisabled})")
    int insertBankInfo(Map<String, Object> bankinfo);

    /**
     * 根据银行卡绑定编号查询银行卡绑定信息
     * @param bandingnum 银行卡绑定编号
     * @return 银行卡绑定信息
     */
    @Select("select binding_num,uid,bankname,address,banknum,binding_time,binding_ip,name,card,phone,isdisabled from lrs_bank_binding where binding_num=#{bandingnum}")
    Map<String,Object> selectBankInfoById(String bandingnum);

    /**
     * 新增用户提现申请
     * @param withdraw 提现申请
     * @return 新增状态（大于0成功，否则失败）
     */
    @Update("insert into yls_withdraw (withdraw_id,uid,money,type,bankname,banknum,bankaddress,withdraw_time,withdraw_ip,status,isdisabled) " +
            "values (#{withdraw_id},#{uid},#{money},#{type},#{bankname},#{banknum},#{bankaddress},#{withdraw_time},#{withdraw_ip},#{status},#{isdisabled})")
    int insertWithDrawApply(Map<String, Object> withdraw);
}
